/**
 * 
 */
package com.qjs.smterp.services;

import java.util.Collections;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.qjs.smterp.jpa.EmployeeDao;
import com.qjs.smterp.jpa.GoodsDao;
import com.qjs.smterp.jpa.GoodsInstockDao;
import com.qjs.smterp.jpa.InstockDao;
import com.qjs.smterp.jpa.StockDao;
import com.qjs.smterp.jpa.UnitDao;
import com.qjs.smterp.model.Employee;
import com.qjs.smterp.model.Goods;
import com.qjs.smterp.model.GoodsInstock;
import com.qjs.smterp.model.Instock;
import com.qjs.smterp.model.Stock;
import com.qjs.smterp.model.Unit;
import com.qjs.smterp.web.utils.SmterpComparator;

/**
 * @author Vostro 3400
 *
 */
@Service("iemService")
@Transactional
public class IEMServiceImpl implements IEMService {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Resource(name="goodsDao")
	private GoodsDao goodsDao;
	
	@Resource(name="stockDao")
	private StockDao stockDao;
	
	@Resource(name="instockDao")
	private InstockDao instockDao;
	
	@Resource(name="unitDao")
	private UnitDao unitDao;

	@Resource(name="employeeDao")
	private EmployeeDao employeeDao;
	
	@Resource(name="goodsInstockDao")
	private GoodsInstockDao goodsInstockDao;
	
	@Override
	public Stock findByStockCode(String code) {
		// TODO Auto-generated method stub
		return stockDao.findByCode(code);
	}

	@Override
	public List<Stock> findALlStock() {
		// TODO Auto-generated method stub
		return stockDao.findByAll();
	}

	@Override
	public void updateStock(Stock stock) {
		// TODO Auto-generated method stub
		stockDao.update(stock);
	}

	@Override
	public void deleteStock(Stock stock) {
		// TODO Auto-generated method stub
		stockDao.delete(stock);
	}

	@Override
	public void createStock(Stock stock) {
		// TODO Auto-generated method stub
		stockDao.save(stock);
		
	}

	@Override
	public Goods findByGoodsCode(String code) {
		// TODO Auto-generated method stub
		return goodsDao.findByCode(code);
	}

	@Override
	public List<Goods> findALlGoods() {
		// TODO Auto-generated method stub
		return goodsDao.findByAll();
	}

	@Override
	public void updateGoods(Goods goods) {
		// TODO Auto-generated method stub
		goodsDao.update(goods);
		
	}

	@Override
	public void createGoods(Goods goods) {
		// TODO Auto-generated method stub
		goodsDao.save(goods);
		
	}

	@Override
	public void deleteGoods(Goods goods) {
		// TODO Auto-generated method stub
		goodsDao.delete(goods);
		
	}

	@Override
	public Instock findByInstockCode(String code) {
		// TODO Auto-generated method stub
		return instockDao.findByCode(code);
	}

	@Override
	public List<Instock> findALlInstock() {
		// TODO Auto-generated method stub
		List<Instock> tmp = instockDao.findByAll();
		Collections.sort(tmp, new SmterpComparator());
		return tmp;
	}

	@Override
	public void updateInstock(Instock instock) {
		// TODO Auto-generated method stub
		instockDao.update(instock);
		
	}

	@Override
	public void createInstock(Instock instock) {
		// TODO Auto-generated method stub
		instockDao.save(instock);
		
	}

	@Override
	public void deleteInstock(Instock instock) {
		// TODO Auto-generated method stub
		instockDao.delete(instock);
		
	}

	@Override
	public Unit findByUnitCode(String code) {
		// TODO Auto-generated method stub
		
		return unitDao.findByCode(code);
	}

	@Override
	public List<Unit> findALlUnits() {
		// TODO Auto-generated method stub
		return unitDao.findByAll();
	}

	@Override
	public void updateUnit(Unit unit) {
		// TODO Auto-generated method stub
		unitDao.update(unit);
		
	}

	@Override
	public void createUnit(Unit unit) {
		// TODO Auto-generated method stub
		unitDao.save(unit);
		
	}

	@Override
	public void deleteUnit(Unit unit) {
		// TODO Auto-generated method stub
		unitDao.delete(unit);
		
	}

	@Override
	public Employee findByEmployeeCode(String code) {
		// TODO Auto-generated method stub
		return employeeDao.findByCode(code);
	}

	@Override
	public List<Employee> findALlEmployees() {
		// TODO Auto-generated method stub
		return employeeDao.findByAll();
	}

	@Override
	public void updateEmployee(Employee employee) {
		// TODO Auto-generated method stub
		employeeDao.update(employee);
		
	}

	@Override
	public void createEmployee(Employee employee) {
		// TODO Auto-generated method stub
		employeeDao.save(employee);
		
	}

	@Override
	public void deleteEmployee(Employee employee) {
		// TODO Auto-generated method stub
		employeeDao.delete(employee);
		
	}

	@Override
	public Goods findByGoodsId(int Id) {
		// TODO Auto-generated method stub
		return goodsDao.findById(Id);
	}

	@Override
	public GoodsInstock findByGoodsInstockCode(String code) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<GoodsInstock> findALlGoodsInstocks() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void updateGoodsInstock(GoodsInstock goodsInstock) {
		// TODO Auto-generated method stub
		goodsInstockDao.update(goodsInstock);
		
	}

	@Override
	public void createGoodsInstock(GoodsInstock goodsInstock) {
		// TODO Auto-generated method stub
		goodsInstockDao.save(goodsInstock);
		
		
	}

	@Override
	public void deleteGoodsInstock(GoodsInstock goodsInstock) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public Unit findByUnitId(int code) {
		// TODO Auto-generated method stub
		return unitDao.findById(code);
	}

	@Override
	public Stock findByStockId(int code) {
		// TODO Auto-generated method stub
		return stockDao.findById(code);
	}
	
	
	
}
